<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      :beforeClose="handleClose4"
      :title="title4"
      :visible.sync="dialogVisible4"
      width="400px">
      <el-form :model="deliverForm" size="mini" label-width="100px"  ref="deliverForm" :rules="rules4">
        <el-form-item label="司机姓名："  prop="driverName"><el-input v-model="deliverForm.driverName"></el-input></el-form-item>
        <el-form-item label="司机手机号：" prop="driverMobile"><el-input v-model="deliverForm.driverMobile"></el-input></el-form-item>
        <el-form-item label="车牌号："  prop="driverTruckNo"><el-input v-model="deliverForm.driverTruckNo"></el-input></el-form-item>
        <el-form-item label="身份证号：" ><el-input v-model="deliverForm.driverIdNumber"></el-input></el-form-item>
        <el-form-item label="运满满订单号：" >
          <el-input v-model="deliverForm.ymmOrderId"></el-input>
        </el-form-item>
        <el-form-item label="运满满运费：" v-if="type != 'pums'" prop="planFreight">
          <el-input v-model="deliverForm.planFreight"></el-input>
        </el-form-item>
        <el-form-item label="备注：">
          <el-input v-model="deliverForm.driverRemark" :autosize="{ minRows: 2, maxRows: 6}" type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="调度员：" prop="logisticsUserId" v-if="type != 'pums'">
          <el-select v-model="deliverForm.logisticsUserId">
            <el-option :value="item.userId" :label="item.realName" v-for="(item,index) in changkuList" :key="index"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="调度员：" v-else>
          <el-select v-model="deliverForm.logisticsUserId">
            <el-option :value="item.userId" :label="item.realName" v-for="(item,index) in changkuList" :key="index"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否整车：" prop="isCompleteCar" v-if="type != 'pums'">
           <el-radio-group v-model="deliverForm.isCompleteCar">
             <el-radio label="整车">整车</el-radio>
<!--             <el-radio label="散货">散货</el-radio>-->
             <el-radio label="拼车">拼车</el-radio>
             <el-radio label="专线">专线</el-radio>
             <el-radio label="铁路">铁路</el-radio>
             <el-radio label="海运">海运</el-radio>
             <el-radio label="快运">快运</el-radio>
             <el-radio label="快递">快递</el-radio>
           </el-radio-group>
        </el-form-item>
        <el-form-item label="是否整车："  v-else>
          <el-radio-group v-model="deliverForm.isCompleteCar">
            <el-radio label="整车">整车</el-radio>
            <el-radio label="散货">散货</el-radio>
            <el-radio label="拼车">拼车</el-radio>
            <el-radio label="专线">专线</el-radio>
            <el-radio label="铁路">铁路</el-radio>
            <el-radio label="海运">海运</el-radio>
            <el-radio label="快运">快运</el-radio>
            <el-radio label="快递">快递</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
<!--      <div style="color:red;padding:0 16px;font-size:12px">注：选择承兑支付时，请确认已有承兑票据</div>-->
      <span slot="footer" class="dialog-footer">
                <el-button @click="handleClose4">取 消</el-button>
                <el-button type="primary" @click="handleConfirm4" :loading="btnLoading4">确 定</el-button>
            </span>
    </el-dialog>
  </div>
</template>
<script>
import "@/utils/jQuery.print"
import {getUserOption} from "../../api/partner";
import {inputDriverInfo} from "../../api/order";

const defaultDeliverForm={
  "billId" : 1, //排货商品记录ID
  "driverName" : "",     //司机姓名
  "driverMobile" : "",   //司机手机号
  "driverTruckNo" : "", //车牌号
  "driverIdNumber" : "" , //身份证号
  "driverRemark" : ""  , //备注
  ymmOrderId:'',
  logisticsUserId:'',
  planFreight:'',
  isCompleteCar:''
};
export default {
  name: "printdischarging",
  data(){
    return {
      deliverForm:JSON.parse(JSON.stringify(defaultDeliverForm)),
      dialogVisible4:false,
      rules4:{
        driverName:[{required: true, trigger: 'blur' ,message: '此项必填',}],
        driverMobile:[{required: true, trigger: 'blur' ,message: '此项必填',}],
        driverTruckNo:[{required: true, trigger: 'blur' ,message: '此项必填',}],
        logisticsUserId:[{required: true, trigger: 'change' ,message: '此项必填',}],
        isCompleteCar:[{required: true, trigger: 'change' ,message: '此项必填',}],
        planFreight:[{required: true, trigger: 'blur' ,message: '此项必填',}],
      },
      btnLoading4:false,
      title4:'',
      changkuList:[],
      type:''

    }
  },

  filters:{

  },

  created() {

  },

  methods:{
    //获取仓库员工
    getChangku(){
      getUserOption({departmentId:4,status:1}).then((res)=>{
        this.changkuList = res
      })
    },


    //显示司机弹窗
    showDialogVisible4(item,title,type){
      this.getChangku();
      console.log("item",item)
      this.title4 = title;
      this.type = type ? type : '';
      this.dialogVisible4 = true;
      this.deliverForm.billId = item.billId;
      this.deliverForm.driverName = item.driverName;
      this.deliverForm.driverMobile = item.driverMobile;
      this.deliverForm.driverTruckNo = item.driverTruckNo;
      this.deliverForm.driverRemark = item.driverRemark;
      this.deliverForm.driverIdNumber = item.driverIdNumber;
      this.deliverForm.ymmOrderId = item.ymmOrderId;
      this.deliverForm.logisticsUserId = item.logisticsUserId ? item.logisticsUserId : '';
      this.deliverForm.planFreight = item.planFreight;
      this.deliverForm.isCompleteCar = item.isCompleteCar ? item.isCompleteCar : '';
      this.$nextTick(()=>{
        this.$refs.deliverForm.clearValidate();
      })
    },


    //关闭司机弹窗
    handleClose4(){
      this.dialogVisible4 = false
    },

    //提交司机信息
    handleConfirm4(){
      this.$refs.deliverForm.validate((valid) => {
        if (valid) {
          this.btnLoading4 = false;
          inputDriverInfo(this.deliverForm).then(response => {
            this.btnLoading4 = false;
            this.handleClose4();
            this.$message({
              message: '提交成功',
              type: 'success',
              duration: 1000
            });
            this.$emit('refresh',this.deliverForm.billId)
          }).catch(() => {
            this.btnLoading4 = false;
          })
        }
      })
    },
  },
}
</script>

<style scoped lang="scss">
    .chexing-con{
      .chexing-title{
          font-weight: bold;
          font-size:14px;
          margin-bottom:10px;
      }
      .chexing-item-list{
        overflow: hidden;
        .chexing-item{
          display: inline-block;
          width:80px;
          height:30px;
          line-height: 30px;
          background: #eee;
          text-align: center;
          color:#666;
          margin-right:10px;
          margin-bottom:10px;
          cursor: pointer;
        }
        .chexing-item.choose{
          background: #f56c6c;
          color:#fff
        }

      }
    }
</style>
